package test.serialization;

import java.io.*;

/**
 * Created by shuoGG on 2018/8/5
 */
public class CloneUtil {

    public static Object deepCopy(Object o) throws IOException, ClassNotFoundException {
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bout);
        oos.writeObject(o);
        ByteArrayInputStream bais = new ByteArrayInputStream(bout.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(bais);
        return ois.readObject();
    }

}
